<?php

namespace app\admin\model;

use think\Model;
use traits\model\SoftDelete;

class Storeper extends Model
{

    use SoftDelete;

    

    // 表名
    protected $table = 'storeper';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'cal_text',
        'status_text'
    ];
    

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    
    public function getCalList()
    {
        #return ['采购入库' => __('采购入库'), '生产入库' => __('生产入库'), '调拨入库' => __('调拨入库'), '调拨出库' => __('调拨出库'), '死亡出库' => __('死亡出库'), '淘汰出库' => __('淘汰出库'), '销售出库' => __('销售出库'), '期初数据' => __('期初数据'), '期末数据' => __('期末数据')];
        return ['调拨入库' => __('调拨入库'), '调拨出库' => __('调拨出库'), '期初数据' => __('期初数据'), '期末数据' => __('期末数据')];
    }

    public function getStatusList()
    {
        #return ['normal' => __('Normal'), 'hidden' => __('Hidden'), 'locked' => __('Locked'), 'deleted' => __('Deleted'), 'checking' => __('Checking')];
        return ['normal' => __('Normal')];
    }


    public function getCalTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['cal']) ? $data['cal'] : '');
        $list = $this->getCalList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }




}
